<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	View mail
</asp:Content>
<asp:Content ContentPlaceHolderID="HeadContent" runat="server">

	<script type="text/javascript">

	function showpreview(idx)
	{
		if( idx == 0 ) 
			$('#htmlpreview').show();
		else
			$('#htmlpreview').hide();
			
		if( idx == 1 ) 
			$('#plaintextpreview').show();
		else
			$('#plaintextpreview').hide();
	}
	
	function confirmandsend()
	{
		var num = '<%= ViewData["NumRecipients"] %>';
		var link = '<%= Url.Action( "StartSend", "Mail",  new { id = ViewData["ID"] } ) %>';		
		if( confirm( "Are you sure you want to send this mail to "+num+" recipients?" ) == 1 )
		{
			location = link;
		}	
	}

	</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<div class="pagetitle">
		<h1>
			Mail: <em>
				<%= ViewData[ "Name" ] %></em>
		</h1>
	</div>
	<div class="pagecontent">
		<table class="columns">
			<tr>
				<td class="column">
					<div class="innercolumn">
						<p class="menu">
							<%= Html.ActionLink("Back to application", "View", "Application", new { ID = ViewData["ApplicationID"] }, null ) %>
							|
							<%= Html.ActionLink("Edit mail", "Edit", new { id = ViewData["ID"] })%>
						</p>
						<h2>
							Test</h2>
						<% using (Html.BeginForm("SendPreview", "Mail", new { id = ViewData["ID"] }, FormMethod.Get))
		 { %>
						<p>
							Send single test-mail to:
							<%= Html.TextBox("email")%>
							<input type="submit" value="Send" />
						</p>
						<%}%>
						<h2>
							Lists and recipients:</h2>
						<ul>
							<% foreach (var l in (ViewData["Lists"] as IList<Mailer.Model.Types.List>)
	   )
		  { %>
							<li>
								<%= Html.Encode(l.Name ) %>
								(<%= l.NumRecipients %>
								recipients) </li>
							<% } %>
						</ul>
					</div>
				</td>
				<td class="column onefourth">
					<div class="innercolumn">
						<p>
							<%= Mailer.Views.ViewHelpers.GetBigMailStatusLegendHTML( (Mailer.Model.Types.Mail)ViewData[ "Mail" ] ) %>
						</p>
					</div>
				</td>
				<td class="column onefourth">
					<div class="innercolumn">
						<p>
							<%= Mailer.Views.ViewHelpers.GetBigMailStatusGraphHTML( (Mailer.Model.Types.Mail)ViewData[ "Mail" ] ) %>
						</p>
					</div>
				</td>
			</tr>
		</table>
		<h2>
			Preview</h2>
		<div id="htmlpreview">
			<div class="tabbedview">
				<div class="tabs">
					<ul>
						<li class="selected"><a href="javascript:showpreview(0);">Rich HTML</a></li>
						<li class=""><a href="javascript:showpreview(1);">Plain text</a></li>
						<li class="last"></li>
					</ul>
				</div>
				<div class="tabcontent">
					<iframe src="<%= ViewData[ "HtmlPreviewURL" ] %>" style="width: 100%; height: 400px;">
					</iframe>
					<p>
						<small>Link: <a href="<%= ViewData[ "HtmlPreviewURL" ] %>">
							<%= ViewData[ "HtmlPreviewURL" ] %></a> </small>
					</p>
				</div>
			</div>
		</div>
		<div id="plaintextpreview" style="display: none;">
			<div class="tabbedview">
				<div class="tabs">
					<ul>
						<li><a href="javascript:showpreview(0);">Rich HTML</a></li>
						<li class="selected"><a href="javascript:showpreview(1);">Plain text</a> </li>
						<li class="last"></li>
					</ul>
				</div>
				<div class="tabcontent">
					<iframe src="<%= ViewData[ "PlaintextPreviewURL" ] %>" style="width: 100%; height: 400px;">
					</iframe>
					<p>
						<small>Public link: <a href="<%= ViewData[ "PlaintextPreviewURL" ] %>">
							<%= ViewData[ "PlaintextPreviewURL" ] %></a> </small>
					</p>
				</div>
			</div>
		</div>
	</div>
	<div class="pageactions">
		<p>
			<button value="Send" onclick="confirmandsend(event)">
				Start sending</button>
		</p>
	</div>
</asp:Content>
